package com.business.api.official.toursism.websitegoods.manager.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.business.api.official.toursism.websitegoods.manager.WebsiteGoodsApiManager;
import com.business.api.official.toursism.websitegoods.mapper.WebsiteGoodsApiMapper;
import com.business.api.official.toursism.websitegoods.vo.WebsiteGoodsApiBriefListVO;
import com.business.api.official.toursism.websitegoods.vo.WebsiteGoodsApiBriefVO;
import com.business.api.official.toursism.websitegoods.vo.WebsiteGoodsApiDetailListVO;
import com.business.api.official.toursism.websitegoods.vo.WebsiteGoodsApiDetailVO;
import com.business.api.official.toursism.websitegoods.vo.data.WebsiteGoodsApiBriefData;
import com.business.api.official.toursism.websitegoods.vo.data.WebsiteGoodsApiDetailData;
import com.business.system.official.toursism.websitegoods.entity.WebsiteGoods;
import com.business.system.official.toursism.websitegoods.manager.WebsiteGoodsManager;
import com.seed.core.exception.ManagerException;
import com.seed.core.pojo.manager.impl.SeedApiManagerImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @description 商品
 * @author CodeGenerator
 * @date   2025-01-25
 * @version V1.0
 */
@Slf4j
@Service("websiteGoodsApiManager")
@Transactional(rollbackFor = ManagerException.class)
public class WebsiteGoodsApiManagerImpl extends SeedApiManagerImpl<WebsiteGoodsApiMapper, WebsiteGoods> implements WebsiteGoodsApiManager {
    @Autowired
    private WebsiteGoodsManager systemManager;

    /**
     * 根据id获取详情VO data
     *
     * @param websiteGoodsId 对象id
     * @return 详情VO data对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiDetailData convertApiDetailData(String websiteGoodsId) throws ManagerException {
        WebsiteGoods websiteGoods = this.getById(websiteGoodsId);
        return this.convertApiDetailData(websiteGoods);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteGoods model
     * @return VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiDetailData convertApiDetailData(WebsiteGoods websiteGoods) throws ManagerException {
        WebsiteGoodsApiDetailData websiteGoodsApiDetailData = new WebsiteGoodsApiDetailData();
        try {
            BeanUtils.copyProperties(websiteGoods, websiteGoodsApiDetailData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteGoods);
        }
        return websiteGoodsApiDetailData;
    }

    /**
     * 根据id获取详情VO
     *
     * @param websiteGoodsId 对象id
     * @return 详情VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiDetailVO getApiDetailVO(String websiteGoodsId) throws ManagerException {
        WebsiteGoodsApiDetailData websiteGoodsApiDetailData = this.convertApiDetailData(websiteGoodsId);
        return new WebsiteGoodsApiDetailVO(websiteGoodsApiDetailData);
    }

    /**
     * 根据对象获取详情VO
     *
     * @param websiteGoods 对象
     * @return 详情VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiDetailVO getApiDetailVO(WebsiteGoods websiteGoods) throws ManagerException {
        WebsiteGoodsApiDetailData websiteGoodsApiDetailData = this.convertApiDetailData(websiteGoods);
        return new WebsiteGoodsApiDetailVO(websiteGoodsApiDetailData);
    }

    /**
     * 根据对象ids获取详情VO data list
     *
     * @param ids 对象ids
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteGoodsApiDetailData> getConvertApiDetailListVOByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteGoods> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteGoods::getId, ids);
        List<WebsiteGoods> websiteGoodsList = this.list(queryWrapper);
        return this.listConvertApiDetailData(websiteGoodsList);
    }

    /**
     * 根据查询条件获取详情VO data list
     *
     * @param queryWrapper 查询条件
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteGoodsApiDetailData> listConvertApiDetailData(Wrapper<WebsiteGoods> queryWrapper) throws ManagerException {
        List<WebsiteGoods> websiteGoodsList = this.list(queryWrapper);
        return this.listConvertApiDetailData(websiteGoodsList);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteGoodsList model列表
     * @return VO对象列表
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteGoodsApiDetailData> listConvertApiDetailData(List<WebsiteGoods> websiteGoodsList) throws ManagerException {
        List<WebsiteGoodsApiDetailData> websiteGoodsApiDetailDataList = new ArrayList<>();
        for (WebsiteGoods websiteGoods : websiteGoodsList) {
            websiteGoodsApiDetailDataList.add(this.convertApiDetailData(websiteGoods));
        }
        return websiteGoodsApiDetailDataList;
    }

    /**
     * 根据对象ids获取详情VO data list
     *
     * @param ids 对象ids
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiDetailListVO getApiDetailListVOByIds(List<String> ids) throws ManagerException {
        return new WebsiteGoodsApiDetailListVO(this.getConvertApiDetailListVOByIds(ids));
    }

    /**
     * 根据查询条件获取详情VO data list
     *
     * @param queryWrapper 查询条件
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiDetailListVO getApiDetailListVO(Wrapper<WebsiteGoods> queryWrapper) throws ManagerException {
        return new WebsiteGoodsApiDetailListVO(this.listConvertApiDetailData(queryWrapper));
    }

    /**
     * 根据对象list获取详情VO data list
     *
     * @param websiteGoodsList 对象list
     * @return 详情VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiDetailListVO getApiDetailListVO(List<WebsiteGoods> websiteGoodsList) throws ManagerException {
        return new WebsiteGoodsApiDetailListVO(this.listConvertApiDetailData(websiteGoodsList));
    }

    /**
     * 根据id获取简略VO data
     *
     * @param websiteGoodsId 对象id
     * @return 简略VO data对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiBriefData convertApiBriefData(String websiteGoodsId) throws ManagerException {
        WebsiteGoods websiteGoods = this.getById(websiteGoodsId);
        return this.convertApiBriefData(websiteGoods);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteGoods model
     * @return VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiBriefData convertApiBriefData(WebsiteGoods websiteGoods) throws ManagerException {
        WebsiteGoodsApiBriefData websiteGoodsApiBriefData = new WebsiteGoodsApiBriefData();
        try {
            BeanUtils.copyProperties(websiteGoods, websiteGoodsApiBriefData);
        } catch (Exception e) {
            throw new ManagerException(e, websiteGoods);
        }
        return websiteGoodsApiBriefData;
    }

    /**
     * 根据id获取简略VO
     *
     * @param websiteGoodsId 对象id
     * @return 简略VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiBriefVO getApiBriefVO(String websiteGoodsId) throws ManagerException {
        WebsiteGoodsApiBriefData websiteGoodsApiBriefData = this.convertApiBriefData(websiteGoodsId);
        return new WebsiteGoodsApiBriefVO(websiteGoodsApiBriefData);
    }

    /**
     * 根据对象获取简略VO
     *
     * @param websiteGoods 对象
     * @return 简略VO对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiBriefVO getApiBriefVO(WebsiteGoods websiteGoods) throws ManagerException {
        WebsiteGoodsApiBriefData websiteGoodsApiBriefData = this.convertApiBriefData(websiteGoods);
        return new WebsiteGoodsApiBriefVO(websiteGoodsApiBriefData);
    }

    /**
     * 根据对象ids获取简略VO data list
     *
     * @param ids 对象ids
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteGoodsApiBriefData> listConvertApiBriefDataByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteGoods> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteGoods::getId, ids);
        List<WebsiteGoods> websiteGoodsList = this.list(queryWrapper);
        return this.listConvertApiBriefData(websiteGoodsList);
    }

    /**
     * 根据查询条件获取简略VO data list
     *
     * @param queryWrapper 查询条件
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteGoodsApiBriefData> listConvertApiBriefData(Wrapper<WebsiteGoods> queryWrapper) throws ManagerException {
        List<WebsiteGoods> websiteGoodsList = this.list(queryWrapper);
        return this.listConvertApiBriefData(websiteGoodsList);
    }

    /**
     * 转换为VO对象
     *
     * @param websiteGoodsList model列表
     * @return VO对象列表
     * @throws ManagerException 通用层异常
     */
    @Override
    public List<WebsiteGoodsApiBriefData> listConvertApiBriefData(List<WebsiteGoods> websiteGoodsList) throws ManagerException {
        List<WebsiteGoodsApiBriefData> websiteGoodsApiBriefDataList = new ArrayList<>();
        for (WebsiteGoods websiteGoods : websiteGoodsList) {
            websiteGoodsApiBriefDataList.add(this.convertApiBriefData(websiteGoods));
        }
        return websiteGoodsApiBriefDataList;
    }

    /**
     * 根据对象ids获取简略VO data list
     *
     * @param ids 对象ids
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiBriefListVO getApiBriefListVOByIds(List<String> ids) throws ManagerException {
        LambdaQueryWrapper<WebsiteGoods> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(WebsiteGoods::getId, ids);
        List<WebsiteGoods> websiteGoodsList = this.list(queryWrapper);
        return new WebsiteGoodsApiBriefListVO(this.listConvertApiBriefData(websiteGoodsList));
    }

    /**
     * 根据查询条件获取简略VO data list
     *
     * @param queryWrapper 查询条件
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiBriefListVO getApiBriefListVO(Wrapper<WebsiteGoods> queryWrapper) throws ManagerException {
        List<WebsiteGoods> websiteGoodsList = this.list(queryWrapper);
        return new WebsiteGoodsApiBriefListVO(this.listConvertApiBriefData(websiteGoodsList));
    }

    /**
     * 根据对象list获取简略VO data list
     *
     * @param websiteGoodsList 对象list
     * @return 简略VO data list对象
     * @throws ManagerException 通用层异常
     */
    @Override
    public WebsiteGoodsApiBriefListVO getApiBriefListVO(List<WebsiteGoods> websiteGoodsList) throws ManagerException {
        return new WebsiteGoodsApiBriefListVO(this.listConvertApiBriefData(websiteGoodsList));
    }
}